//
//  MyProfileViewController.m
//  DebugDemo
//
//  Created by XFB on 2018/11/21.
//  Copyright © 2018年 ZhouCheng. All rights reserved.
//

#import "MyProfileViewController.h"
#import "MyProfileCell.h"
#import "MyProfileItemModel.h"
#import "MyProfileSectionModel.h"
#import "SettingViewController.h"

@interface MyProfileViewController () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *sectionArray;

@end

@implementation MyProfileViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupBasicSet];
    [self setupUI];
}

- (void)setupBasicSet
{
    self.view.backgroundColor = UIColorFromRGB(0xFFFFFF);
    self.navigationItem.title = @"个人中心";
    
    [self.view addSubview:self.tableView];
}

- (void)setupUI
{
    __weak typeof(self) weakSelf = self;
    
    MyProfileItemModel *item1 = [[MyProfileItemModel alloc] init];
    item1.themeName = @"我的投诉";
    item1.themeImage = [UIImage imageNamed:@"myprofile_theme_complaint"];
    item1.accessoryType = UserCenterAccessoryTypeIndicator;
    item1.ExecuteCode = ^{
        SettingViewController *vc = [[SettingViewController alloc] init];
        [weakSelf.navigationController pushViewController:vc animated:YES];
    };
    
    MyProfileItemModel *item2 = [[MyProfileItemModel alloc] init];
    item2.themeName = @"我的关注";
    item2.themeImage = [UIImage imageNamed:@"myprofile_theme_focus"];
    item2.accessoryType = UserCenterAccessoryTypeIndicator;
    item2.ExecuteCode = ^{
        NSLog(@"我的关注点击");
    };
    
    MyProfileItemModel *item3 = [[MyProfileItemModel alloc] init];
    item3.themeName = @"我的收藏";
    item3.themeImage = [UIImage imageNamed:@"myprofile_theme_collect"];
    item3.accessoryType = UserCenterAccessoryTypeIndicator;
    
    MyProfileItemModel *item4 = [[MyProfileItemModel alloc] init];
    item4.themeName = @"我的话题";
    item4.themeImage = [UIImage imageNamed:@"myprofile_theme_topic"];
    item4.accessoryType = UserCenterAccessoryTypeIndicator;
    
    MyProfileItemModel *item5 = [[MyProfileItemModel alloc] init];
    item5.themeName = @"我的提问";
    item5.themeImage = [UIImage imageNamed:@"myprofile_theme_question"];
    item5.accessoryType = UserCenterAccessoryTypeIndicator;
    
    /// 第一组
    MyProfileSectionModel *section1 = [[MyProfileSectionModel alloc] init];
    section1.itemArray = @[item1, item2, item3, item4, item5];

    MyProfileItemModel *item6 = [[MyProfileItemModel alloc] init];
    item6.themeName = @"积分商城";
    item6.themeImage = [UIImage imageNamed:@"myprofile_theme_question"];
    item6.accessoryType = UserCenterAccessoryTypeIndicator;
    
    /// 第二组
    MyProfileSectionModel *section2 = [[MyProfileSectionModel alloc] init];
    section2.itemArray = @[item6];
    
    MyProfileItemModel *item7 = [[MyProfileItemModel alloc] init];
    item7.themeName = @"账号与安全";
    item7.themeImage = [UIImage imageNamed:@"myprofile_theme_question"];
    item7.accessoryType = UserCenterAccessoryTypeIndicator;
 
    /// 第三组
    MyProfileSectionModel *section3 = [[MyProfileSectionModel alloc] init];
    section3.itemArray = @[item7];
    
    self.sectionArray = @[section1, section2, section3];
}

#pragma mark --- <UITableViewDataSource>

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.sectionArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    MyProfileSectionModel *sectionModel = self.sectionArray[section];
    return sectionModel.itemArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyProfileCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyProfileCell"];
//    cell.transform = CGAffineTransformMakeRotation(M_PI/2);
    MyProfileSectionModel *sectionModel = self.sectionArray[indexPath.section];
    MyProfileItemModel *itemModel = sectionModel.itemArray[indexPath.row];
    cell.itemModel = itemModel;
    return cell;
}

#pragma mark --- <UITableViewDelegate>
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    MyProfileSectionModel *sectionModel = self.sectionArray[indexPath.section];
    MyProfileItemModel *itemModel = sectionModel.itemArray[indexPath.row];
    if (itemModel.ExecuteCode) {
        itemModel.ExecuteCode();
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 200;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return [UIView new];
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [UIView new];
}

#pragma mark --- <Loading Lazy>
- (UITableView *)tableView
{
    if (_tableView == nil) {
//        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, ScreenW, ScreenH-NavBarHeight) style:UITableViewStyleGrouped];
//        _tableView.backgroundColor = UIColorFromRGB(0xF5F5F5);
//        _tableView.delegate = self;
//        _tableView.dataSource = self;
//        [_tableView registerClass:[MyProfileCell class] forCellReuseIdentifier:@"MyProfileCell"];
//        _tableView.transform = CGAffineTransformMakeRotation(- M_PI / 2);//旋转-90度

        CGFloat f = (ScreenH-NavBarHeight-ScreenW)*0.5;
//        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(-f, f, ScreenH-NavBarHeight, ScreenW) style:UITableViewStylePlain];
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, ScreenW, ScreenH-NavBarHeight) style:UITableViewStyleGrouped];
        _tableView.dataSource = self;
        _tableView.delegate = self;
//        _tableView.transform = CGAffineTransformMakeRotation(-M_PI/2);
        _tableView.backgroundColor = UIColorFromRGB(0xF2F2F2);
        _tableView.pagingEnabled = YES;
        _tableView.showsVerticalScrollIndicator = NO;
        [_tableView registerClass:[MyProfileCell class] forCellReuseIdentifier:@"MyProfileCell"];
    }
    return _tableView;
}


@end
